/*	FormItem.java
 *
 *	Copyright (c) Manateem Challenge Group, Zaia Group, and contributors 2010
 *
 *	This file is part of MSGToolSuite_Swing ('this project').
 *
 *	This project is free software: you can redistribute it and/or modify it
 *	under the terms of the GNU General Public License as published by the Free
 *	Software Foundation, either version 3 of the License, or (at your option)
 *	any later version.
 *
 *	This project is distributed in the hope that it will be useful, but WITHOUT
 *	ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 *	FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 *	more details.
 *
 *	You should have received a copy of the GNU General Public License along with
 *	this project. If not, see <http://www.gnu.org/licenses/>.
 */
package edu.bu.manateem.msg.gui.component;

import java.awt.Dimension;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JComponent;
import javax.swing.JLabel;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *	<p>
 *	
 *	</p>
 *
 *
 *	@author
 *		Christopher Jacobs
 *
 *	@version
 *		1.0
 *
 *	@changelog
 *		May 21, 2010	- Version 1.0.
 */
public abstract class FormItem
	extends JComponent
{
	/*
	 * TYPES
	 */

	/*
	 * CONSTANTS
	 */

	// Serialize
	private static final long serialVersionUID = 1L;
	// Logging
	private static final Logger LOG = LoggerFactory.getLogger(FormItem.class);
	
	// layout
	protected static final int DEFAULT_GAP_X = 5;
	protected static final int DEFAULT_GAP_Y = 0;
	protected static final Dimension DEFAULT_GAP_SIZE =
		new Dimension(FormItem.DEFAULT_GAP_X,FormItem.DEFAULT_GAP_Y);
	
	// default form stuff
	protected static final String DEFAULT_LABEL = "";
	protected static final String DEFAULT_DELIMITER = ":";
	protected static final String DEFAULT_DESC = "";
	
	/*
	 * FIELDS
	 */
	private JLabel label;
	private JLabel delimiter = new JLabel(FormItem.DEFAULT_DELIMITER);
	protected JComponent item;
	private JLabel desc;
	
	/*
	 * CONSTRUCTORS
	 */

	public FormItem()
	{
		this(FormItem.DEFAULT_LABEL);
	}
	
	public FormItem(String label)
	{
		this(label,FormItem.DEFAULT_DESC);
	}
	
	public FormItem(String label,String desc)
	{
		super();
		
		setLabel(label); // initLabel();
		setDescription(desc); // initDesc();
		initItem();
		init();
	}
	
	/*
	 * INITIALIZERS
	 */

	/*
	 * METHODS
	 */

	public String getDescription()
	{
		return desc.getText();
	}
	
	public String getLabel()
	{
		return label.getText();
	}
	
	protected void init()
	{
		FormItem.LOG.debug("init FormItem");
		
		// behaviors
		setVisible(true);
		
		// layout
		setLayout(new BoxLayout(this,BoxLayout.LINE_AXIS));
		
		// finish
		add(label);
		add(Box.createRigidArea(FormItem.DEFAULT_GAP_SIZE));
		add(delimiter);
		add(Box.createRigidArea(FormItem.DEFAULT_GAP_SIZE));
		add(item);
		add(Box.createRigidArea(FormItem.DEFAULT_GAP_SIZE));
		add(desc);
	}
	
	protected abstract void initItem();
	
	public void setDelimiter(String delimiter)
	{
		this.delimiter = new JLabel(delimiter);
	}
	
	public void setDescription(String desc)
	{
		this.desc = new JLabel(desc);
		repaint();
	}
	
	public void setLabel(String label)
	{
		this.label = new JLabel(label);
		repaint();
	}
}
